package com.example.mypplication.multiscreen

import android.app.Application
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.mypplication.MyApplication
import com.example.mypplication.R

class MutilScreenActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        setCustomDentisy(this,MyApplication.application, 160)
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_mutil_screen)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
    }

    private fun setCustomDentisy(activity: MutilScreenActivity, application: Application, designWidthDP: Int) {
        val appDisplayMetrics = application.resources.displayMetrics
        val targetDentisity = 1.0f * appDisplayMetrics.widthPixels/designWidthDP
        val targetDentisityDpi = (targetDentisity*160).toInt()
        appDisplayMetrics.density = targetDentisity
        appDisplayMetrics.densityDpi = targetDentisityDpi

        val activityDisplayMetrics = activity.resources.displayMetrics
        activityDisplayMetrics.density = targetDentisity
        activityDisplayMetrics.densityDpi = targetDentisityDpi

    }
}